/******************************************************************************
 * Project: Processor Affinity Manager                                        *
 * File:    ShellExtension.cs                                                 *
 * Author:  Aaron Jones                                                       *
 * Version: 1                                                                 *
 *                                                                            *
 * Description:                                                               *
 *    This file contains a class that maintains the shell extention used by   *
 *    the processor affinity manager.                                         *
 ******************************************************************************/

using Microsoft.Win32;

namespace ProcessorAffinityManager
{
    /// <summary>
    /// Encapsulates operations regarding the shell extension installed by the
    /// processor affinity manager.
    /// </summary>
    public class ShellExtension
    {
        private static readonly ManagedRegistryKey m_RootKey = new ManagedRegistryKey(
            Registry.ClassesRoot, @"*\shell\Run with Processor Affinity...");
        private static readonly ManagedRegistryKey m_Key = new ManagedRegistryKey(
            Registry.ClassesRoot, @"*\shell\Run with Processor Affinity...\command");

        /// <summary>
        /// Whether or not the shell extention is installed on the current machine.
        /// </summary>
        public static bool Exists
        {
            get
            {
                return m_Key.Exists();
            }
        }

        /// <summary>
        /// If the shell extention is not already installed, install the shell extension.
        /// </summary>
        public static void Install()
        {
            if(!Exists)
                m_Key.SetValue(null, ConfigurationFile.InstallDirectory + Shortcut.ExecutableName + " %1");
        }

        /// <summary>
        /// If the shell extension is installed, remove it.
        /// </summary>
        public static void Remove()
        {
            if (Exists)
            {
                m_Key.Delete();
                m_RootKey.Delete();
            }
        }
    }
}
